//
//  GoOutMainHeadView.m
//  ArtOfLiving
//
//  Created by 刘虎 on 16/4/30.
//  Copyright © 2016年 刘虎. All rights reserved.
//

#import "GoOutMainHeadView.h"
#import "GoOutMainheadViewModel.h"
#import "GoOutSpeciallTopicAllViewController.h"
#import "GoOutSpecialTopicDetialViewController.h"

typedef enum {
    
    GoOutMainHeadViewImageTagTop = 100,
    GoOutMainHeadViewImageTagLeft,
    GoOutMainHeadViewImageTagRight
}GoOutMainHeadViewImageTag;


@interface GoOutMainHeadView ()

@property (weak, nonatomic) IBOutlet UIImageView *topImageView;
@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
@property (weak, nonatomic) IBOutlet UIImageView *rightImageView;

@end

@implementation GoOutMainHeadView

- (void)setHeadViewModel:(NSArray *)headViewModel {

    SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority;
    
    for (int i = 0; i < 3; i++) {
        
        UIImageView *imageView = [self viewWithTag:GoOutMainHeadViewImageTagTop+i];
        [imageView sd_setImageWithURL:[NSURL URLWithString:[(GoOutMainheadViewModel *)headViewModel[i] photo]] placeholderImage:[UIImage imageNamed:@"travelPlaceholder.png"] options:options];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
        [imageView addGestureRecognizer:tapGesture];
        _headViewModel = headViewModel;
    }
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    self.topImageView.tag = GoOutMainHeadViewImageTagTop;
    self.leftImageView.tag = GoOutMainHeadViewImageTagLeft;
    self.rightImageView.tag = GoOutMainHeadViewImageTagRight;
}


- (void)tapGestureAction:(UITapGestureRecognizer *)sender {
    
    UIImageView *imageView = (UIImageView *)[sender view];
    GoOutMainheadViewModel *model = self.headViewModel[imageView.tag-GoOutMainHeadViewImageTagTop];
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    GoOutSpecialTopicDetialViewController *goOutSpecialTopicDetialVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"GoOutSpecialTopicDetialViewController"];
    goOutSpecialTopicDetialVC.htmlUrl = model.url;
    goOutSpecialTopicDetialVC.navcTitle = model.title;
    [self.naVC pushViewController:goOutSpecialTopicDetialVC animated:YES];
}


- (IBAction)checkMoreTopicClick:(UIButton *)sender {
    
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    GoOutSpeciallTopicAllViewController *goOutSpeciallTopicAllVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"GoOutSpeciallTopicAllViewController"];
    [self.naVC pushViewController:goOutSpeciallTopicAllVC animated:YES];
}





@end
